package yunquan.wang.core.dao.springdata;

import java.io.Serializable;

import javax.persistence.EntityManager;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.support.JpaRepositoryFactory;
import org.springframework.data.repository.core.RepositoryMetadata;

public class BaseRepositoryFactory extends JpaRepositoryFactory {

	/**
	 * @param entityManager
	 */
	public BaseRepositoryFactory(EntityManager entityManager) {

		super(entityManager);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.springframework.data.jpa.repository.support.GenericJpaRepositoryFactory
	 * #getTargetRepository(java.lang.Class, javax.persistence.EntityManager)
	 */
	@Override
	@SuppressWarnings("unchecked")
	protected JpaRepository<?, ?> getTargetRepository(RepositoryMetadata  metadata, EntityManager em) {
		return new BaseRepositoryImpl<Object, Serializable>((Class)metadata.getDomainType(), em);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.springframework.data.repository.support.RepositoryFactorySupport#
	 * getRepositoryBaseClass()
	 */
	@Override
	protected Class<?> getRepositoryBaseClass(RepositoryMetadata metadata) {

		return BaseRepositoryImpl.class;
	}
}
